#duuuid.py
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from lib.myDataStructure.ds import *
import wsgiref.handlers
import os

class MainPage(webapp.RequestHandler):
    def get(self):
        q = db.GqlQuery("SELECT * FROM UUID order by uid" )
        #q = db.GqlQuery("SELECT * FROM UUID" )
        
        du_cnt=0
        
        #where True:
        l=[]
        
        for uuid in q:
            l.append(uuid.uid)
        
        length=len(l)
        
        index=0
        while True:
            if(index+1 == length):
                break
                
            u=l[index]
            u2=l[index+1]
            
            if u == u2:
                du_cnt=du_cnt+1
                
            index=index+1
            
            
        #while True:
                                
            
        
            
        template_values = {
            'cnt': q.count(),
            'dup_cnt':du_cnt,
            'ulist':q
        }
        path = os.path.join(os.path.dirname(__file__), 'template/duuuid.html')
        self.response.out.write(template.render(path, template_values))
        
        
    def post(self):        
        pass
        

def main():
  application = webapp.WSGIApplication(
                                       [('/duuuid', MainPage)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()